<!--#include file="./header.inc"-->
<%

select case aq
	case "save" 			: 	call save
	case "edit" 			: 	call edit
	case "delete" 			: 	call delete
	case "status" 			: 	call status
	case "editbatch" 		: 	call editBatch
	case "savebatch" 		: 	call saveBatch
	case else 				: 	call index
end select

call db.close()

function index()
	dim keyword
	keyword = admin.filter(request("keyword"))
	sql = "select id,title,content,orderID,isStop from cj_our"
	if keyword <> "" then sql = sql & " where title like '%" & keyword & "%' or content like '%" & keyword & "%'"
	sql = sql & " Order by orderID asc"
	temp = db.arrayData(sql, page, rows)
	infoTotal = temp(0)
	data = temp(1)
	%><!--#include file="./view/our.index.html"--><%
end function

function edit()
	data = array("", "", "", "", "", "")
	if iid > 0 then
		set rs = db.exec("select title,infoViewID,picUrl,orderID,isStop,content from cj_our where id=" & iid, 1)
		if rs.eof then admin.message "id不存在！"
		data = rs
		set rs = nothing
	end if
	%><!--#include file="./view/our.edit.html"--><%
end function

function save()
	title = admin.filter(request.form("title"))
	content = trim(request.form("content"))
	if title = "" then admin.message "简介标题不能为空！"
	if len(content) < 10 then admin.message "简介内容字数太少了！"
	content = admin.enUploadDir(content)
	if iid > 0 then
		set rs = db.exec("select * from cj_our where id=" & iid, 3)
		if rs.eof then admin.message "id不存在！"
	else
		set rs = db.exec("select * from cj_our", 3)
		rs.AddNew
	end if
	rs("title") = title
	rs("content") = content
	rs("picUrl") = admin.filter(request.form("picUrl"))
	rs("isStop") = admin.isCheck(request.form("isStop"))
	rs("infoViewID") = app.int(request.form("infoViewID"))
	rs("orderID") = app.int(request.form("orderID"))
	rs.update
	rs.close : set rs = nothing
	if iid > 0 then
		admin.back "修改成功！", "返回列表", "?q=index"
	else
		admin.back "添加成功！", "继续添加", "?q=edit"
	end if
end function

function editBatch()
	%><!--#include file="./view/our.editBatch.html"--><%
end function

function saveBatch()
	dim isOrderID, orderID, isInfoViewID, iInfoViewID
	isOrderID = admin.isCheck(request.form("isOrderID"))
	isInfoViewID = admin.isCheck(request.form("isInfoViewID"))
	if not(isOrderID) and not(isInfoViewID) then admin.message "需要选择一项！"
	if isInfoViewID then
		iInfoViewID = app.int(request.form("infoViewID"))
	end if
	orderID = app.int(request.form("orderID"))
	set rs = db.exec("select * from cj_our where id in(" & batchId & ")", 3)
	do until rs.eof
		if isInfoViewID then
		    rs("infoViewID") = iInfoViewID
		end if
		if isOrderID then
		    rs("orderID") = orderID
		end if
		rs.update
		rs.movenext
	loop
	rs.close : set rs = nothing
	admin.back "修改成功！", "返回列表首页", "?q=index"
end function

function delete()
	call db.exec("Delete from cj_our where id in(" & batchId & ")", 1)
	app.json "删除成功！", 0
end function

function status()
	dim isStop, msg
    isStop = app.cj_bool(request("isStop"))
    msg = "启用"
    if isStop then
        msg = "禁用"
    end if
	call db.exec("update cj_our set isStop=" & isStop & " where id in(" & batchId & ")", 1)
	app.json msg & "成功！", 0
end function

%>